/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ems_packet_is_in_fragment.c                      */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"
#include "frmem.h"

#include <tibcoems/config.h>
#include <tibcoems/ems_core.h>
#include <tibcoems/ems_comm.h>
#include <tibcoems/ems_packet.h>

extern void __ems_destroy_packet(L7_ems_packet **pp_st_ems_packet);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    L7_ems_packet *p_st_ems_packet = NULL;
    p_st_ems_packet = (L7_ems_packet *) frmalloc(sizeof(L7_ems_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_ems_packet);
    memset(p_st_ems_packet, 0x00, sizeof(L7_ems_packet));

    CU_ASSERT_EQUAL(ems_init_packet(p_st_ems_packet), FR_SUCC);

    p_st_ems_packet->fragment_state = APM_EMS_FRAGMENT_INIT;
    CU_ASSERT_EQUAL(ems_packet_is_in_fragment(p_st_ems_packet), FR_NO);

    __ems_destroy_packet(&p_st_ems_packet);
}

static void __case2(void)
{
    L7_ems_packet *p_st_ems_packet = NULL;
    p_st_ems_packet = (L7_ems_packet *) frmalloc(sizeof(L7_ems_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_ems_packet);
    memset(p_st_ems_packet, 0x00, sizeof(L7_ems_packet));

    CU_ASSERT_EQUAL(ems_init_packet(p_st_ems_packet), FR_SUCC);

    p_st_ems_packet->fragment_state = APM_EMS_FRAGMENT_NEED_NEXT_REQ_PACKET;
    CU_ASSERT_EQUAL(ems_packet_is_in_fragment(p_st_ems_packet), FR_YES);

    __ems_destroy_packet(&p_st_ems_packet);
}

static void __case3(void)
{
    L7_ems_packet *p_st_ems_packet = NULL;
    p_st_ems_packet = (L7_ems_packet *) frmalloc(sizeof(L7_ems_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_ems_packet);
    memset(p_st_ems_packet, 0x00, sizeof(L7_ems_packet));

    CU_ASSERT_EQUAL(ems_init_packet(p_st_ems_packet), FR_SUCC);

    p_st_ems_packet->fragment_state = APM_EMS_FRAGMENT_NEED_NEXT_RESP_PACKET;
    CU_ASSERT_EQUAL(ems_packet_is_in_fragment(p_st_ems_packet), FR_YES);

    __ems_destroy_packet(&p_st_ems_packet);
}

int add_suite_ems_packet_is_in_fragment(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ems_packet_is_in_fragment()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
